﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Sinobase.DataQuality.KnowledgeBase;
using System.Linq.Expressions;
using System.Reflection;
using Littlebeer.MDM.MSO;
namespace Demo
{
    class Program
    {
        static DataTable WorkTable = new DataTable();
        static KnowledgeBaseProviderBase kb;
        static void Main(string[] args)
        {
            //LoadDemoTable();
            ShowDataColumns(WorkTable);
            //kb = KnowledgeBaseContext.Get(1);

            while (1 == 1)
            {
                Console.WriteLine("Input your command \r\n0:Test\r\n1:\r\n2:\r\n3:\r\n");
                var commond = Console.ReadLine();
                Action(commond);
            }
        }
        static void Action(string command)
        {
            switch (command)
            {
                case ("0"):
                    {
                        TestSingleDomain(WorkTable);
                        break;
                    }
                case ("1"):
                    {
                        //test3();
                        //LoadSQLDemoTable();
                        break;
                    }
                case ("2"):
                    {
                        //LoadDemoTable3();
                        break;
                    }
                case ("4"):
                    {
                        test4();
                        break;
                    }
                case ("5"):
                    {
                        test5();
                        break;
                    }
                case ("6"):
                    {
                        test6();
                        break;
                    }
                case ("7"):
                    {
                        test7();
                        break;
                    }
                case ("8"):
                    {
                        test8();
                        break;
                    }
                default:
                    {
                        Console.WriteLine("You choose other!");
                        break;
                    }
            }
        }
        //        static void LoadDemoTable()
        //        {
        //            DM.IO.OledbLoader myload = new DM.IO.OledbLoader();
        //            string connectionString = @"Provider=SQLOLEDB;Data Source=.;
        //Initial Catalog=NBTC;Integrated Security = SSPI;";
        //            string sql = "select * from customer";
        //            WorkTable = myload.ToTable(connectionString, sql);
        //            Console.WriteLine("Sample data count:" + WorkTable.Rows.Count.ToString());
        //        }
        //        static void LoadDemoTable2()
        //        {
        //            DM.IO.OledbLoader myload = new DM.IO.OledbLoader();
        //            string connectionString = Littlebeer.ConnectionStringHelper.OleDB.Excel.OleDBExcelConnection.Get("C:\\Users\\Dragon\\Desktop\\xls.xlsx");
        //            string sql = "select * from [sheet1$]";
        //            //WorkTable = myload.ToTable(connectionString, sql);
        //            WorkTable = Littlebeer.DataSource.OleDBDataSource.ToTable(connectionString, sql);
        //            Console.WriteLine("Sample data count:" + WorkTable.Rows.Count.ToString());
        //            ShowDataColumns(WorkTable);
        //        } 
        //        static void LoadDemoTable3()
        //        {
        //            DM.IO.OledbLoader myload = new DM.IO.OledbLoader();
        //            string connectionString = Littlebeer.ConnectionStringHelper.OleDB.Access.OleDBAccessConnectionstring.Get("C:\\Users\\Dragon\\Documents\\accdb.mdb");
        //            string sql = "select * from [表1]";
        //            WorkTable = myload.ToTable(connectionString, sql);
        //            Console.WriteLine("Sample data count:" + WorkTable.Rows.Count.ToString());
        //            ShowDataColumns(WorkTable);
        //        }
        //static void LoadSQLDemoTable()
        //        {
        //            DM.IO.OledbLoader myload = new DM.IO.OledbLoader();
        //            string connectionString = Littlebeer.ConnectionStringHelper.Oledb.SqlServer.Get(".", "NBTC");
        //            string sql = "select * from [user]";
        //            WorkTable = myload.ToTable(connectionString, sql);
        //            Console.WriteLine("Sample data count:" + WorkTable.Rows.Count.ToString());
        //        }
        //static void LoadSQLDemoTable2()
        //        {
        //            DM.IO.OledbLoader myload = new DM.IO.OledbLoader();
        //            string connectionString = Littlebeer.ConnectionStringHelper.OLEDB.DataBase.SqlServer.GetString(".", "NBTC","SA","SA");
        //            string sql = "select * from [user]";
        //            WorkTable = myload.ToTable(connectionString, sql);
        //            Console.WriteLine("Sample data count:" + WorkTable.Rows.Count.ToString());
        //        }
        static void ShowDataColumns(DataTable dt)
        {
            Console.WriteLine("\r\n Columns:\r\n");
            foreach (DataColumn item in dt.Columns)
            {
                Console.WriteLine(item.ColumnName.Trim() + "\t");
            }
        }
        static void TestSingleDomain(DataTable dt)
        {
            //执行清洗方法，第一个参数可以传入的值：参考1.6预制的域
            foreach (DataRow row in dt.Rows)
            {
                if (row["mobile"].ToString() != "")
                {
                    var result = kb.DomainClean("移动电话", row["mobile"].ToString());
                    if (result.CleanResultType != CleanResultType.正确)
                    {
                        Console.WriteLine(string.Format("Mobile:{0} Erro:{1} \t Old:{2}\tNew{3})\r\n", row["mobile"].ToString(), result.Description, result.OldValue, result.NewValue));
                    }
                }
            }

        }
























        //static void test2()
        //{
        //    DM.IO.OledbLoader myload = new DM.IO.OledbLoader();
        //    string fileName = "C:\\Users\\Dragon\\Desktop\\NBTC\\Files\\template\\26225.xlsx";
        //    string mExcelCon = @"Provider=Microsoft.ACE.OLEDB.12.0;";
        //    string mConnectionString; 
        //    mConnectionString = mExcelCon + "Data Source=" + fileName + 
        //            ";Extended Properties=" + Convert.ToChar(34).ToString() + 
        //            "Excel 12.0;HDR=Yes" + Convert.ToChar(34).ToString();
        //    string sql = "select * from [26225-20130217231238$]";
        //    DataTable dt = myload.ToTable(mConnectionString, sql);
        //    Console.Write(dt.Rows.Count.ToString());
        //    Console.ReadLine();
        //}

        //static void test3()
        //{
        //    Littlebeer.Deduplicate.Models.DeduplicateRule rule1 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
        //    rule1.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;

        //    Littlebeer.Deduplicate.Models.DeduplicateRuleField field11 = new Littlebeer.Deduplicate.Models.DeduplicateRuleField();
        //    field11.FieldName = "Company";
        //    field11.Function = "";
        //    List<string> arg111 = new List<string>();
        //    arg111.Add("");
        //    field11.Args = arg111;


        //    rule1.DeduplicateRuleFields.Add(field11);
        //    rule1.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Phone", Function = "", Args = new List<string>() { "" } });

        //    Littlebeer.Deduplicate.Models.DeduplicateRule rule2 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
        //    rule2.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;
        //    rule2.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Company", Function = "", Args = new List<string>() { "" } });
        //    rule2.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Fex", Function = "", Args = new List<string>() { "" } });

        //    Littlebeer.Deduplicate.Models.DeduplicateRule rule3 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
        //    rule3.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;
        //    rule3.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Company", Function = "", Args = new List<string>() { "" } });
        //    rule3.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Address", Function = "", Args = new List<string>() { "" } });


        //    Littlebeer.Deduplicate.Models.DeduplicateRule rule4 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
        //    rule4.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;
        //    rule4.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Company", Function = "", Args = new List<string>() { "" } });

        //    Littlebeer.Deduplicate.Models.DeduplicateRule rule5 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
        //    rule5.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;
        //    rule5.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Fex", Function = "", Args = new List<string>() { "" } });

        //     Littlebeer.Deduplicate.Models.DeduplicateRule rule6 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
        //     rule6.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;
        //     rule6.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Phone", Function = "", Args = new List<string>() { "" } });


        //     Littlebeer.Deduplicate.Models.DeduplicateRule rule7 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
        //     rule7.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;
        //     rule7.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Address", Function = "", Args = new List<string>() { "" } });

        //    List<Littlebeer.Deduplicate.Models.DeduplicateRule> RuleList=new List<Littlebeer.Deduplicate.Models.DeduplicateRule>();
        //    RuleList.Add(rule1);
        //    RuleList.Add(rule2);
        //     RuleList.Add(rule3);
        //    RuleList.Add(rule4);
        //     RuleList.Add(rule5);
        //    RuleList.Add(rule6);
        //     RuleList.Add(rule7);
        //    var orderrule= Littlebeer.Deduplicate.DeduplicateRulesManager.GetDeduplicateRuleGroup(RuleList);

        //}

        private static DataTable GetTestTable()
        {
            DataTable result = new DataTable();
            result.Columns.Add("ID");
            result.Columns.Add("Name");
            result.Columns.Add("Phone");
            result.Columns.Add("Fax");
            result.Columns.Add("Address");

            DataRow row = result.NewRow();
            row["ID"] = 1;
            row["Name"] = "dragondragondragondragondragondragondragon1";
            row["Phone"] = "010-51652500-615";
            row["Address"] = "chaoyang road 69";
            row["Fax"] = "010-67654543";
            result.Rows.Add(row);

            DataRow row2 = result.NewRow();
            row2["ID"] = 2;
            row2["Name"] = "dragondragondragondra";
            row2["Phone"] = "010-51652500-615";
            row2["Address"] = "chaoyang road 70";
            row2["Fax"] = "010-67654543";
            result.Rows.Add(row2);

            DataRow row3 = result.NewRow();
            row3["ID"] = 3;
            row3["Name"] = "dragondragondragondragondragondragondragon1";
            row3["Phone"] = "010-51652500-615";
            row3["Address"] = "chaoyang road 70";
            row3["Fax"] = "010-67654543";
            result.Rows.Add(row3);
            for (int i = 0; i < 1000000; i++)
            {
                DataRow rows = result.NewRow();
                rows["ID"] = i + 4;
                rows["Name"] = "dragonwang" + (4 + i).ToString().Replace("9", "");
                rows["Phone"] = "010-51652500-6195" + (4 + i).ToString();
                rows["Address"] = "chaoyang road 70" + (4 + i).ToString();
                rows["Fax"] = "010-67654843" + (4 + i).ToString();
                result.Rows.Add(rows);
            }
            DataColumn[] pk = new DataColumn[1];
            pk[0] = result.Columns["ID"];

            result.PrimaryKey = pk;

            return result;
        }
        private static DataTable GetTestTable2()
        {
            DataTable result = new DataTable();
            result = Littlebeer.DataSource.OleDBDataSource.ToTable(Littlebeer.ConnectionStringHelper.OleDB.Excel.OleDBExcelConnection.Get("C:\\DB\\沈阳.xlsx"), "select Comp_ID,Comp_Nme,Comp_LegalPerson,Comp_UpDateDate,comp_addr,comp_phone,Comp_Fax from [sheet1$]");
            DataColumn[] pk = new DataColumn[1];
            pk[0] = result.Columns["Comp_ID"];

            result.PrimaryKey = pk;

            return result;
        }
        private static List<Littlebeer.Deduplicate.Models.DeduplicateRule> GetTestDepdulicateRules()
        {
            List<Littlebeer.Deduplicate.Models.DeduplicateRule> result = new List<Littlebeer.Deduplicate.Models.DeduplicateRule>();

            //Littlebeer.Deduplicate.Models.DeduplicateRule rule1 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
            //rule1.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;
            //rule1.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Name", DeduplicateFunctions = new List<Littlebeer.Deduplicate.Models.DeduplicateFunction>() { new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Single, FunctionName = "", Orders = 0, Args = new List<string>() { } } } });
            //result.Add(rule1);

            //Littlebeer.Deduplicate.Models.DeduplicateRule rule2 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
            //rule2.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;
            //rule2.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Phone", DeduplicateFunctions = new List<Littlebeer.Deduplicate.Models.DeduplicateFunction>() { new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Single, FunctionName = "", Orders = 0, Args = new List<string>() { } } } });
            //result.Add(rule2);

            Littlebeer.Deduplicate.Models.DeduplicateRule rule3 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
            rule3.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Auto;
            rule3.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Phone", DeduplicateFunctions = new List<Littlebeer.Deduplicate.Models.DeduplicateFunction>() { new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Single, FunctionName = "", Orders = 0, Args = new List<string>() { } } } });
            rule3.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Fax", DeduplicateFunctions = new List<Littlebeer.Deduplicate.Models.DeduplicateFunction>() { new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Single, FunctionName = "", Orders = 0, Args = new List<string>() { } } } });
            rule3.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Name", DeduplicateFunctions = new List<Littlebeer.Deduplicate.Models.DeduplicateFunction>() { new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Single, FunctionName = "", Orders = 0, Args = new List<string>() { } }, new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Multiple, FunctionName = "Similar", Orders = 0, Args = new List<string>() { "0.05" } } } });
            result.Add(rule3);

            return result;
        }
        private static List<Littlebeer.Deduplicate.Models.DeduplicateRule> GetTestDepdulicateRules2()
        {
            List<Littlebeer.Deduplicate.Models.DeduplicateRule> result = new List<Littlebeer.Deduplicate.Models.DeduplicateRule>();

            Littlebeer.Deduplicate.Models.DeduplicateRule rule1 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
            rule1.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;
            rule1.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "comp_addr", DeduplicateFunctions = new List<Littlebeer.Deduplicate.Models.DeduplicateFunction>() { new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Single, FunctionName = "", Orders = 0, Args = new List<string>() { } } } });
            result.Add(rule1);

            Littlebeer.Deduplicate.Models.DeduplicateRule rule2 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
            rule2.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Manual;
            rule2.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "comp_phone", DeduplicateFunctions = new List<Littlebeer.Deduplicate.Models.DeduplicateFunction>() { new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Single, FunctionName = "", Orders = 0, Args = new List<string>() { } } } });
            result.Add(rule2);

            Littlebeer.Deduplicate.Models.DeduplicateRule rule3 = new Littlebeer.Deduplicate.Models.DeduplicateRule();
            rule3.RuleType = Littlebeer.Deduplicate.Models.DeduplicateRuleType.Auto;
            rule3.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "comp_addr", DeduplicateFunctions = new List<Littlebeer.Deduplicate.Models.DeduplicateFunction>() { new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Single, FunctionName = "", Orders = 0, Args = new List<string>() { } } } });
            rule3.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "comp_phone", DeduplicateFunctions = new List<Littlebeer.Deduplicate.Models.DeduplicateFunction>() { new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Single, FunctionName = "", Orders = 0, Args = new List<string>() { } } } });
            //rule3.DeduplicateRuleFields.Add(new Littlebeer.Deduplicate.Models.DeduplicateRuleField() { FieldName = "Name", DeduplicateFunctions = new List<Littlebeer.Deduplicate.Models.DeduplicateFunction>() { new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Single, FunctionName = "", Orders = 0, Args = new List<string>() { } }, new Littlebeer.Deduplicate.Models.DeduplicateFunction() { DeduplicateFunctionType = Littlebeer.Deduplicate.Models.DeduplicateFunctionType.Multiple, FunctionName = "Similar", Orders = 0, Args = new List<string>() { "0.05" } } } });
            result.Add(rule3);

            return result;
        }

        public static void test4()
        {

            DataTable dt = GetTestTable();
            DateTime t_start = DateTime.Now;
            List<Littlebeer.Deduplicate.Models.DeduplicateRule> rules = GetTestDepdulicateRules();
            Littlebeer.Deduplicate.DeduplicateManager deduplicatemanager = new Littlebeer.Deduplicate.DeduplicateManager(dt, "ID", rules);
            var result = deduplicatemanager.GetResult();
            DateTime t_end = DateTime.Now;
            TimeSpan ts = t_end - t_start;

            result.AsParallel().ForAll(d =>
            {
                Console.WriteLine(string.Format("Reason:{0}\tIDS:{1}", d.DeduplicateReason, d.IDs));
            });
            Console.WriteLine(string.Format("Group Count:{0},Second:{1}", result.Count, ts.TotalSeconds.ToString()));
            GC.Collect();
        }
        static void test5()
        {
            string str1 = "dragondragondragondragondragondragondragon1";
            string str2 = "dragondragondragondragondragondragondragon1";
            decimal result = new Littlebeer.Deduplicate.Functions.Similar().GetSimilarRate(str1, str2);
        }
        public static void test6()
        {
            DateTime t_startReadData = DateTime.Now;
            Console.WriteLine(string.Format("{0}\t Start Read Data", t_startReadData));
            DataTable dt = GetTestTable2();
            DateTime t_endReadData = DateTime.Now;
            Console.WriteLine(string.Format("{0}\t End Read Data,Use Second:{1}", t_endReadData, (t_endReadData - t_startReadData).TotalSeconds));
            DateTime t_start = DateTime.Now;
            Console.WriteLine(string.Format("{0}\t Start Deduplicate", t_start));
            List<Littlebeer.Deduplicate.Models.DeduplicateRule> rules = GetTestDepdulicateRules2();
            Littlebeer.Deduplicate.DeduplicateManager deduplicatemanager = new Littlebeer.Deduplicate.DeduplicateManager(dt, "Comp_ID", rules);
            var result = deduplicatemanager.GetResult();
            DateTime t_end = DateTime.Now;
            TimeSpan ts = t_end - t_start;
            //DateTime t_startclean = DateTime.Now;
            //var newresult = new Littlebeer.Deduplicate.DeduplicateManager().ClearDeduplicateResult(result);
            //DateTime t_endclean = DateTime.Now;
            //TimeSpan tsclean = t_endclean - t_startclean;
            result.AsParallel().ForAll(d =>
            {
                try
                {
                    Console.WriteLine(string.Format("Reason:{0}\tIDS:{1}", d.DeduplicateReason, d.IDs));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });
            Console.WriteLine(string.Format("Group Count:{0},Deduplicate Second:{1}", result.Count, ts.TotalSeconds.ToString()));
            GC.Collect();


        }
        public static void test7()
        {
            Expression<Func<int, bool>> lambda = num => num < 5;
            Expression<Func<int, int, int>> lan = (a, b) => a + b;
            //Console.WriteLine(lan.Compile().DynamicInvoke(1,2));
            List<Littlebeer.Deduplicate.Models.DeduplicateRule> rulelist = GetTestDepdulicateRules2();
            var query = from a in rulelist
                        group a by new { a.RuleType } into g
                        select new { };
            ParameterExpression FirstVar = ParameterExpression.Parameter(typeof(int), "first");
            ParameterExpression SecondVar = ParameterExpression.Parameter(typeof(int), "second");
            BinaryExpression ex = BinaryExpression.Multiply(FirstVar, SecondVar);
            var lamex = Expression.Lambda<Func<int, int, int>>(ex, FirstVar, SecondVar);
            //Console.WriteLine(lamex.Compile().DynamicInvoke(6, 6));

            ParameterExpression s1 = ParameterExpression.Parameter(typeof(string), "str1");
            ParameterExpression s2 = ParameterExpression.Parameter(typeof(string), "str2");
            ConstantExpression getbigger = ParameterExpression.Constant(new biggetter());
            MethodInfo mi = typeof(biggetter).GetMethod("getbigger", new Type[] { typeof(string), typeof(string) });
            MethodCallExpression getex = Expression.Call(getbigger, mi, s1, s2);
            Expression<Func<string, string, string>> mylamex = Expression.Lambda<Func<string, string, string>>(getex, s1, s2);
            Console.WriteLine(mylamex.Compile().DynamicInvoke("6", "2555555555555556"));
        }
        public static void test8()
        {
           

            //Littlebeer.MDM.MSO.EntityManager mg = new Littlebeer.MDM.MSO.EntityManager();
            //var group1=new Littlebeer.MDM.MSO.
            //group1.Add("公司名称");
            //mg.EntityIndentityGroups.Add(group1);
            DataTable DataSource = Littlebeer.DataSource.OleDBDataSource.ToTable(Littlebeer.ConnectionStringHelper.OleDB.Excel.OleDBExcelConnection.Get("C:\\DB\\客户数据.xlsx"), "select 公司名称,区号,电话,传真,省份,城市,地址 from [sheet1$]");
            
//            DataTable MainTable = Littlebeer.DataSource.SqlClientDataSource.ToTable(Littlebeer.ConnectionStringHelper.SqlClient.SqlConnection.Get(".", "NBTC"), @"SELECT 
//CompanyName,
//AreaCode,
//DirectTel,
//FAX,
//Province,
//City,
//Address
//FROM Customer");

            
            Littlebeer.Common.FieldMapping.MappingManager MapManager = new Littlebeer.Common.FieldMapping.MappingManager();
            
            Littlebeer.Common.FieldMapping.FieldPairModel pari1 = 
                new Littlebeer.Common.FieldMapping.FieldPairModel() 
                { Left = new Littlebeer.Common.FieldMapping.FieldModel() 
                { FieldName = "公司名称", FieldType = "" }, 
                Right = new Littlebeer.Common.FieldMapping.FieldModel() 
                { FieldName = "CompanyName", FieldType = "" }
                };

            MapManager.Add(pari1);

            Littlebeer.Common.FieldMapping.FieldPairModel pari2 =
               new Littlebeer.Common.FieldMapping.FieldPairModel()
               {
                   Left = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "区号", FieldType = "" },
                   Right = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "AreaCode", FieldType = "" }
               };

            MapManager.Add(pari2);

            Littlebeer.Common.FieldMapping.FieldPairModel pari3 =
               new Littlebeer.Common.FieldMapping.FieldPairModel()
               {
                   Left = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "电话", FieldType = "" },
                   Right = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "DirectTel", FieldType = "" }
               };

            MapManager.Add(pari3);

            Littlebeer.Common.FieldMapping.FieldPairModel pari4 =
              new Littlebeer.Common.FieldMapping.FieldPairModel()
              {
                  Left = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "传真", FieldType = "" },
                  Right = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "FAX", FieldType = "" }
              };

            MapManager.Add(pari4);

            Littlebeer.Common.FieldMapping.FieldPairModel pari5 =
             new Littlebeer.Common.FieldMapping.FieldPairModel()
             {
                 Left = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "省份", FieldType = "" },
                 Right = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "Province", FieldType = "" }
             };

            MapManager.Add(pari5);

            Littlebeer.Common.FieldMapping.FieldPairModel pari6 =
          new Littlebeer.Common.FieldMapping.FieldPairModel()
          {
              Left = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "城市", FieldType = "" },
              Right = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "City", FieldType = "" }
          };

            MapManager.Add(pari6);

            Littlebeer.Common.FieldMapping.FieldPairModel pari7 =
          new Littlebeer.Common.FieldMapping.FieldPairModel()
          {
              Left = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "地址", FieldType = "" },
              Right = new Littlebeer.Common.FieldMapping.FieldModel() { FieldName = "Address", FieldType = "" }
          };

            MapManager.Add(pari7);
           
            string targetconn=Littlebeer.ConnectionStringHelper.SqlClient.SqlConnection.Get(".","NBTC");
           
            Littlebeer.MDM.MSO.EntityManager EntityManager = new Littlebeer.MDM.MSO.EntityManager(targetconn);
            List<Littlebeer.MDM.MSO.EntityMatchErroModel> errolist = new List<EntityMatchErroModel>();
            new Littlebeer.MDM.MSO.KeyMatcher().MatchKeys(DataSource, MapManager.Maps, targetconn, errolist);

        }
    }
    public class biggetter
    {
        public string getbigger(string str1, string str2)
        {
            return (str1.Length > str2.Length) ? str1 : str2;
        }
    }
}
